<template>
  <div class="workers">
    <div @click="scan(2)" class="scan-style">扫码查看入沈备案</div>
    <!-- <div @click="scan(1)" class="scan-style-b scan-style">扫码查看出沈备案</div> -->
  </div>
</template>

<script>
import { Dialog, Toast } from 'vant'
import { distinguishSstErCode, getSstCodeForWorker } from '../../api/gov/home/index'
var setInter
export default {
  components: {},
  props: {},
  data () {
    return {
    }
  },
  mounted () {
    localStorage.setItem('type', 'workers')
    console.log(localStorage.getItem('type'))
    // 2分钟刷新一次 防止token过期
    setInter = setInterval(() => { this.$router.go(0) }, 120000)
  },
  methods: {
    scan (value) {
      console.log(3546)
      console.log(this.$hdsdk)
      this.$hdsdk.scanQrCode().then(ret => {
        console.log(ret, '扫码返回值')
        if (!!ret && ret.code == 0 && !!ret.data && !!ret.data.scanResult) {
          console.log(ret, '返回值')
          getSstCodeForWorker().then(res => {
            if (res.data.errcode == 9933) return Toast.fail('此账号无审批权限')
            distinguishSstErCode({ ecQrCode: ret.data.scanResult }).then(ret => {
              if (ret.data.errcode != 0) return Toast.fail(ret.data.errmsg)
              if (ret.data.data.errcode != 0) return Toast.fail(ret.data.data.errmsg)
              clearInterval(setInter)
              console.log(ret, '获取用户信息')
              this.$router.push({ name: 'workersInfo', query: { cardNo: ret.data.data.data.cardNo, value } })
            })
          })
        } else { Dialog.alert({ message: ret.codeDescription }).then(() => {}) }
      }).catch(res => { console.log('reject ----', res) })
    }
  }
}
</script>
<style lang="less" scoped>
.workers{
  height: 100vh;
  display: flex;
  // justify-content: center;
  align-items: center;
  flex-direction: column;
  background: url('../../assets/images/bl.png')no-repeat;
  background-size: 100% 100%;
  .scan-style{
    margin-top: 120px;
    width: 85vw;
    height: 200px;
    background: #469af0;
    color: white;
    border-radius: 20px;
    text-align: center;
    line-height: 200px;
  }
  .scan-style-b{
    margin-top: 100px;
  }
}
</style>
